package com.yyds.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yyds.common.MyJSON;
import com.yyds.mapper.NatInfoMapper;
import com.yyds.pojo.NatInfo;
import com.yyds.service.NatInfoService;
import com.yyds.vo.EchartPieVo;
import com.yyds.vo.EarchBarVo;
import com.yyds.vo.NatInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 请不要模仿我
 *
 * @author lxy
 * com.yyds.service.impl.
 */
@Service
public class NatInfoServiceImpl implements NatInfoService {
    @Autowired
    private NatInfoMapper mapper;
    @Override
    public int deleteByPrimaryKey(Integer infoId) {
        return mapper.deleteByPrimaryKey(infoId);
    }

    @Override
    public int insert(NatInfo record) {
        return mapper.insert(record);
    }

    @Override
    public int insertSelective(NatInfo record) {
        return mapper.insertSelective(record);
    }

    @Override
    public NatInfo selectByPrimaryKey(Integer infoId) {
        return mapper.selectByPrimaryKey(infoId);
    }

    @Override
    public int updateByPrimaryKeySelective(NatInfo record) {
        return mapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(NatInfo record) {
        return mapper.updateByPrimaryKey(record);
    }

    @Override
    public MyJSON<NatInfo> natInfoPageData(Map<String, Object> params) {
        Integer page = Integer.parseInt(params.get("page")+"");
        Integer limit = Integer.parseInt(params .get("limit")+"");

        PageHelper.startPage(page,limit);
        List<NatInfo> natInfo =  mapper.findAllNatInfo(params);

        // mybatis 的分页数据结构
        PageInfo<NatInfo> natHospitalPageInfo = new PageInfo<>(natInfo);
        // 把mybatis 的分页数据结构中的 数据 封装到 layui的 分页数据结构中
        MyJSON<NatInfo> natHospitalVo = new MyJSON<>();
        natHospitalVo.setCode(0);
        natHospitalVo.setMsg("学生分页列表数据");
        natHospitalVo.setCount(natHospitalPageInfo.getTotal());  // 总记录数
        natHospitalVo.setData(natHospitalPageInfo.getList());  // 分页列表数据
        return natHospitalVo;
    }

    @Override
    public List<EarchBarVo> countData() {

        return mapper.countData();
    }

    @Override
    public List<EchartPieVo> countresultData() {
        return mapper.countresultData();
    }

    @Override
    public int deleteAll(String str) {
        List<Integer> list = new ArrayList();
        String[] split = str.split("-");
        for (String s : split) {
            list.add(Integer.valueOf(s));
        }

        return mapper.deleteAll(list);
    }

    @Override
    public MyJSON<NatInfoVo> natInfoAllPageData(Map<String, Object> params) {
        Integer page = Integer.parseInt(params.get("page")+"");
        Integer limit = Integer.parseInt(params .get("limit")+"");

        PageHelper.startPage(page,limit);
        List<NatInfoVo> natInfo =  mapper.findInfoAllPageData(params);

        // mybatis 的分页数据结构
        PageInfo<NatInfoVo> natHospitalPageInfo = new PageInfo<>(natInfo);
        // 把mybatis 的分页数据结构中的 数据 封装到 layui的 分页数据结构中
        MyJSON<NatInfoVo> natHospitalVo = new MyJSON<>();
        natHospitalVo.setCode(0);
        natHospitalVo.setMsg("zhengque");
        natHospitalVo.setCount(natHospitalPageInfo.getTotal());  // 总记录数
        natHospitalVo.setData(natHospitalPageInfo.getList());  // 分页列表数据
        return natHospitalVo;
    }
}
